www.gusucode.com > VC++ 新手写的简单客房管理系统源码程序 > VC++ 新手写的简单客房管理系统源码程序/code/tot/InroomDialog.cpp
//Download by http://www.NewXing.com // InroomDialog.cpp : implementation file // #include "stdafx.h" #include "tot.h" #include "InroomDialog.h" #include "FangDialog.h" #include "FangSet.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CInroomDialog dialog CInroomDialog::CInroomDialog(CWnd* pParent /*=NULL*/) : CDialog(CInroomDialog::IDD, pParent) { //{{AFX_DATA_INIT(CInroomDialog) m_lname = _T(""); m_lpersonid = _T(""); m_lroomid = 0; m_lsex = -1; m_ldays = 0; m_lclass = -1; m_inf = _T(""); //}}AFX_DATA_INIT //if(!m_database.Open(NULL,FALSE,FALSE,"ODBC;DSN=Room")) //{AfxMessageBox("不能打开数据库");} //m_set.Open(); } void CInroomDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CInroomDialog) DDX_Control(pDX, IDC_COMBO1, m_num); DDX_Text(pDX, IDC_NAME, m_lname); DDX_Text(pDX, IDC_PERSON, m_lpersonid); DDX_Text(pDX, IDC_ROOM, m_lroomid); DDX_Radio(pDX, IDC_RADIO_M, m_lsex); DDX_Text(pDX, IDC_DAYS, m_ldays); DDX_Radio(pDX, IDC_LCLASS1, m_lclass); DDX_Text(pDX, IDC_INF, m_inf); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CInroomDialog, CDialog) //{{AFX_MSG_MAP(CInroomDialog) ON_BN_CLICKED(IDC_BUTTONASK, OnButtonask) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CInroomDialog message handlers void CInroomDialog::OnOK() //1 { // TODO: Add extra validation here CDatabase m_database; if(!m_database.Open(_T("Room"))) AfxMessageBox("数据库打开出错"); m_set.Open(); CFangSet m_fset; m_fset.Open(); CString msg,tmsg; char string[10]; int tag=0; int sel; CTime m_current; UpdateData(true); if(m_lname.IsEmpty()) {AfxMessageBox("请输入用户名");} else if(m_lpersonid.IsEmpty()) {AfxMessageBox("请输入身份证");} else if(m_lroomid==0) { MessageBox("房间号不对","客人登记失败",MB_OK|MB_ICONWARNING); GetDlgItem(IDC_ROOM)->SetFocus(); } else if(m_ldays==0) { MessageBox("住宿天数不对","客人登记失败",MB_OK|MB_ICONWARNING); GetDlgItem(IDC_DAYS)->SetFocus(); } else { while(!m_fset.IsEOF()) { if(m_fset.m_roomID==m_lroomid) { if(m_fset.m_state=="空") tag=1; else tag=0; break; } else {m_fset.MoveNext();} } } /* if(tmp[0]>306||tmp[0]<100) {AfxMessageBox("请先查询"); }*/ /* else{ for(int i=1;i<=K;i++) {if(tmp[i-1]==m_lroomid) {tag=0;break;} }*/ if(tag==0) { AfxMessageBox("此房有人住客人登记失败",MB_OK|MB_ICONWARNING); GetDlgItem(IDC_ROOM)->SetFocus(); } if(tag==1) { //2 try{//3 m_set.AddNew(); UpdateData(true); sel=m_num.GetCurSel(); m_set.m_people=sel+1; if(sel+1<m_fset.m_max) {//4 m_set.m_roomID=m_lroomid; m_set.m_name=m_lname; m_set.m_personID=m_lpersonid; m_set.m_information=m_inf; if(m_lsex==0) m_set.m_sex="男"; else m_set.m_sex="女"; m_set.m_day=m_ldays; m_set.m_logtime=m_current.GetCurrentTime(); msg+="\r\n\n";msg+="客人登记成功"; // m_bLogin=TRUE; UpdateData(true); // if(m_lclass==0) { m_set.m_class="一级"; msg+="\r\n"; msg+="费用为:"; _gcvt(m_ldays*100,10,string); msg+=string; m_set.m_cost=m_ldays*100; } else if(m_lclass==1) { m_set.m_class="二级"; msg+="\r\n"; msg+="费用为:"; _gcvt(m_ldays*70,10,string); msg+=string; m_set.m_cost=m_ldays*70; } else { m_set.m_class="三级"; msg+="\r\n"; msg+="费用为:"; _gcvt(m_ldays*40,10,string); msg+=string; m_set.m_cost=m_ldays*40; } m_set.Update(); AfxMessageBox(msg); CDialog::OnOK();} else { AfxMessageBox("人数太多!");} }//3 catch(CDBException*pe) {AfxMessageBox(pe->m_strError); pe->Delete(); } }//2 m_set.Close(); }//1 void CInroomDialog::OnButtonask() { // TODO: Add your control notification handler code here CFangDialog fdlg; fdlg.DoModal(); /* CString msg; char pi[6]; K=0; UpdateData(true); msg+="\r\n\n"; if(m_lclass==-1) { AfxMessageBox("请先选择房间级别",MB_OK); } else{ m_set.Requery(); m_set.MoveFirst(); if(m_lclass==0) { while(!m_set.IsEOF()) { if(m_set.m_roomID>100&&m_set.m_roomID<107) {K++;tmp[K-1]=m_set.m_roomID;} m_set.MoveNext(); } msg+="一级客房(住了人):"; } else if(m_lclass==1) { while(!m_set.IsEOF()) { if(m_set.m_roomID>200&&m_set.m_roomID<207) {K++;tmp[K-1]=m_set.m_roomID;} m_set.MoveNext(); } msg+="二级客房(住了人):"; } else if(m_lclass==2) { while(!m_set.IsEOF()) { if(m_set.m_roomID>300&&m_set.m_roomID<307) {K++;tmp[K-1]=m_set.m_roomID;} m_set.MoveNext(); } msg+="三级客房(住了人):"; } if(K==0) {tmp[0]=109;MessageBox("此等级房间均空!!","查询空房",MB_OK|MB_ICONASTERISK);} else{ _gcvt(K,6,pi); msg+=pi; msg+="间"; msg+="\r\n"; msg+="分别为:"; for(int i=1;i<=K;i++) { _gcvt(tmp[i-1],6,pi); msg+="\r"; msg+=pi; msg+="\r\n"; } MessageBox(msg,"查询空房",MB_OK|MB_ICONASTERISK);} }*/ } BOOL CInroomDialog::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here int i=1; char tem[6]; for(i;i<=15;i++) { _gcvt(i,6,tem); m_num.AddString(tem); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }